using BSDS.Core.Data.Local.Csv.Parsing;
using BSDS.Core.Data.Local.Xml.Parsing;

namespace BSDS.Core.Data.Local
{
    public class LocalDataParserFactory
    {
        private readonly DataFormatRecognizer formatRecognizer;

        public LocalDataParserFactory(DataFormatRecognizer formatRecognizer)
        {
            this.formatRecognizer = formatRecognizer;
        }

        public IParser Create(string filename)
        {
            var dataFormat = formatRecognizer.Recognize(filename);

            if(dataFormat == DataFormat.Xml)
            {
                return new XmlFormatParser();
            }

            return new CsvFormatParser(dataFormat);
        }
    }
}